package guzb.cnblogs.classloader.third;

import java.util.ArrayList;
import java.util.List;

/**
 * 物理接口槽，一个接口槽中安装有多个接口
 *
 * @author 顾志兵
 * @mail ipiger@163.com
 * @since 2024-05-21
 */
public class SocketSlot {

    /** 接口槽的编号 */
    private int number;

    /** 接口支持的接口数量 */
    private int socketCount;

    /** 已连接的接口列表 */
    private List<Socket> connectedSockets = new ArrayList<>();

    public SocketSlot(int number, int socketCount) {
        this.number = number;
        this.socketCount = socketCount;
    }

    public int getNumber() {
        return number;
    }

    public int getSocketCount() {
        return socketCount;
    }

    public List<Socket> getConnectedSockets() {
        return connectedSockets;
    }

    public void connect(Socket socket) {
        if (this.connectedSockets.size() >= socketCount) {
            System.out.println("接口已全部占用");
            return;
        }
        connectedSockets.add(socket);
    }
}
